package com.etop.learnapp.activity;

import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.CardView;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;

import com.etop.learnapp.R;

public class MainActivity extends AppCompatActivity
         {
    private Toolbar toolbar;
    private DrawerLayout drawer;
    private ActionBarDrawerToggle toggle;
    private CardView cardViewCr1;
    private CardView cardViewCr2;
    private CardView cardViewCr3;
    //DrawerLayout中的左侧菜单控件
    private NavigationView mNavigationView;
    //DrawerLayout控件
    private DrawerLayout mDrawerLayout;
    private ActionBarDrawerToggle mDrawerToggle;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mymain);
        toolbar = (Toolbar) findViewById(R.id.toolbar_include);

        setSupportActionBar(toolbar);
        cardViewCr3 = (CardView) findViewById(R.id.cv_main_course1);
        cardViewCr3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, ChapterActivity.class);
                intent.putExtra("chapterSize", 11);
                intent.putExtra("courseSelect", 1);
                startActivity(intent);
            }
        });
        mDrawerLayout = (DrawerLayout) this.findViewById(R.id.drawer_layout);
        mNavigationView = (NavigationView) this.findViewById(R.id.navigation_view);
        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar,R.string.drawer_open,
                 R.string.drawer_close);
        mDrawerToggle.syncState();
        mDrawerLayout.setDrawerListener(mDrawerToggle);
        setupDrawerContent(mNavigationView);


    }

             private void setupDrawerContent(NavigationView navigationView) {
                 navigationView.setNavigationItemSelectedListener(
                         new NavigationView.OnNavigationItemSelectedListener() {
                             @Override
                             public boolean onNavigationItemSelected(MenuItem menuItem) {
                                 switch (menuItem.getItemId()) {
                                     case R.id.nav_apply:
                                         startActivity(new Intent(MainActivity.this,ApplyActivity.class));

                                         break;
                                     case R.id.nav_info:

                                         startActivity(new Intent(MainActivity.this,InfoActivity.class));
                                      //   StartTask startTask = new StartTask();

                                     //    startTask.execute(MainActivity.this);
                                         break;

                                 }

                        //         mDrawerLayout.closeDrawers();
                                 return false;
                             }
                         });
             }

    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }
class StartTask extends AsyncTask<Context,Integer,String> {


    @Override
    protected String doInBackground(Context...contexts) {

        return "success start";
    }

}
}

